import * as types from './action-types'
export function CounteReducer(state = { count: 100, type: '偶数' }, action) {
  switch (action.type) {
    case types.ADD:
      return {
        ...state,
        count: state.count + action.num,
        type: (state.count + action.num) % 2 ? "奇数" : "偶数"
      }
    case types.MINUS:
      return {
        ...state,
        count: state.count - action.num,
        type: (state.count - action.num) % 2 ? "奇数" : "偶数"
      }

    default:
      return {
        ...state
      }
  }
}

export function ColorReducer(state = { color: 'red' }, action) {
  if (action.type == types.CHANGECOLOR) {
    return {
      color: action.col
    }
  } else {
    return {
      ...state
    }
  }
}